<template>
	<view class="page-wrap" :data-theme="theme" :class="theme" :style="globalColor.style">
		<view class="spaceBar" :style="{ height: statusBarHeight + 'px' }"></view>
		<view class="spaceHead"></view>
		<HeadCustom id="HeadCustom" :isSpace="false" title="" :isAppBtn="false" :isHome="false">
			<view class="fboxRow Ycenter Xcenter download" slot="right" @click="downPDF"><text class="bwfont bw-xiazai"></text>下载 </view>
		</HeadCustom>
		<web-view :src="pdfUrl" :style="{'margin-top': topHeight+'px' }"></web-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				theme: 'bks-theme',
				globalColor: getApp().globalData.globalColor,
				pdfUrl:'',
				from:'',
				statusBarHeight: getApp().globalData.statusBarHeight,
				topHeight: 44,
				downUrl: '',
				downName: '',
			}
		},                                                                     
		onLoad(option) {
			if (option && option.url) {
				this.pdfUrl = '/hybrid/html/web/viewer.html?file='+decodeURI(option.url)
				this.downUrl = decodeURI(option.url)
				this.downName = decodeURI(option.name)
			}
		},
		onReady() {
			const { bw_params } = getApp().getBWData(['bw_link', 'bw_params']);
			uni.createSelectorQuery(this).select('.spaceHead').boundingClientRect(data => {
				this.statusBarHeight = bw_params.statusBarHeight;
				if(data.height){
					this.topHeight = Number(data.height) + Number(this.statusBarHeight)
				}else{
					this.topHeight = 44 + Number(this.statusBarHeight)
				}
			}).exec()
		},
		mounted() {
		},
		// onLoad() {
		// 	/**
		// 	 * 浏览情景
		// 	 */
			
		// 	// 浏览情景1:浏览本地的pdf文件
		// 	this.pdfUrl = '/hybrid/html/web/viewer.html?file='+url
			
		// 	// 浏览情景2:浏览在线的pdf文件
		// 	// this.pdfUrl = '/hybrid/html/web/viewer.html?file='+encodeURIComponent(pdfUrl)
		// },
		methods: {
			downPDF(){
				const data = {
					type: 'vitaDownload',
					fileUrl: this.downUrl,
					fileName: this.downName+'.pdf'
				}
				this.$bridge.callHandler('recruitHandler', data, () => {
					console.log('recruitHandler', '返回')
				})
			},
			/**
			 * 下载情景
			 */
			downloadPdfClick(){
				// 下载情景1:h5内嵌app,通过分享给朋友的方式进行下载
				if(this.from == 'app'){
					let item = 'http://自己的域名/hybrid/html/web/pdf.html?shareUrl='+encodeURIComponent(this.bgUrl)
								+'&shareTitle=PDF文件';
					window.open(item);
					return;
					
				}else if(this.from == 'wx wq'){
				// 下载情景2:h5内嵌微信小程序,从h5页面跳转到小程序页面后,然后通过调用小程序原生API进行下载
				// 注意: 先要引入微信jssdk  [命令: npm install jweixin-module]
					// this.$wx.miniProgram.navigateTo({
					// 	url: '/pages/pdf/pdf_download?pdf='+ encodeURIComponent(this.bgUrl) //小程序页面链接
					// });
				}
				
			}
		}
	}
</script>

<style lang="scss" scoped>
.spaceHead {
	width: 100%;
	height: 88rpx;
}
.page-wrap{background-color:rgba(64, 64, 64, 1);}
.page-wrap /deep/ .bw-fanhui{color: #fff;}
.page-wrap /deep/ .bw-fanhui:before{color: #fff;}
.page-wrap .download{color: #fff;}
.page-wrap .download .bwfont{margin-right: 6rpx;}
</style>
